package com.xfb.jdbc.sqlSession;

import com.xfb.jdbc.config.XMLConfigBuilder;
import com.xfb.jdbc.pojo.Configuration;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

/**
 * @author xing fang bin
 * @date 2021/6/28 0028 22:39
 * @description
 */
public class SqlSessionBuilder {
    public SqlSessionFactory build(InputStream inputStream) throws PropertyVetoException, DocumentException {

        // 第一步：使用dom4j读取配置文件，将配置文件解析出来的内容封装到Configuration中
        XMLConfigBuilder xmlConfigBuilder = new XMLConfigBuilder();
        Configuration configuration = xmlConfigBuilder.parseConfig(inputStream);

        // 第二步：创建SqlSessionFactory对象:工厂类，生产sqlSession会话对象
        DefaultSqlSessionFactory defaultSqlSessionFactory = new DefaultSqlSessionFactory(configuration);


        return defaultSqlSessionFactory;
    }
}
